package cn.sumpu.app.coolsk.dao.impl;

import java.util.List;
import java.util.Map;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.sumpu.app.coolsk.dao.PointDao;
import cn.sumpu.app.coolsk.domain.Keep;
import cn.sumpu.app.coolsk.domain.Point;
import cn.sumpu.app.coolsk.exception.AppBusinessException;

public class PointDaoImpl extends SqlSessionDaoSupport implements PointDao{
	
	private static final Logger logger = LoggerFactory.getLogger(MemberDaoImpl.class);
	
	
	
	 /**
	  * 
	  */
	@Override
	public void insertPoint(Point point)throws AppBusinessException {
		
		try { 
			getSqlSession().insert("cn.sumpu.app.coolsk.persistence.PointMapper.insertPoint",
					point);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insertPoint database failure.", e);
			}
			throw new AppBusinessException("insertPoint database failure.", e);
		}
	}
	//我的积分
	@SuppressWarnings("unchecked")
	@Override
	public List<Point> getPointListByMid(Map<String, Object> map) throws AppBusinessException {
		try {
		   return getSqlSession().selectList("cn.sumpu.app.coolsk.persistence.PointMapper.getPointListByMid",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getPointListByMid database failure.", e);
			}
			throw new AppBusinessException("getPointListByMid database failure.", e);
		}
	}
	//我的积分记录总数
	@Override
	public int getPointCountByMid(Map<String, Object> map)throws AppBusinessException {
		try {
			Object obj = (Integer) getSqlSession()
					.selectOne("cn.sumpu.app.coolsk.persistence.PointMapper.getPointCountByMid",
							map);
			return (Integer) (obj == null ? 0 : obj);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getPointCountByMid database failure.", e);
			}
			throw new AppBusinessException("getPointCountByMid database failure.", e);
		}
	}

}
